package twobranchsearch.searchbsf;

import twobranchTree.preorderTraversal.TreeNode;

/**
 * @Date 2020/03/11
 * @author 王光浩
 * @Thinking 使用递归方式+前序遍历。
 */
public class MyMethodOne {
	private TreeNode target;
	private int value;
    public TreeNode searchBST(TreeNode root, int val) {
    	this.value=val;
    	recursively(root);
    	return target;
    }
    private void recursively(TreeNode root) {
    	if(root==null || this.target!=null)return;
    	if(root.val==this.value)this.target=root;
    	if(root.val>this.value)recursively(root.left);
    	else recursively(root.right);
    }
}
